﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Resxus.ViewModel;

namespace Resxus.View
{
    /// <summary>
    /// ResourceEditView.xaml에 대한 상호 작용 논리
    /// </summary>
    public partial class ResourceEditView : UserControl
    {
        public ResourceEditView()
        {
            InitializeComponent();            
        }

        private void UserControl_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            ResourceEditVM ovm = e.OldValue as ResourceEditVM;
            if (ovm != null)
            {
                ovm.RequestScrollToView -= new Action<Resxus.Model.ResourceRecord>(vm_RequestScrollToView);
            }

            ResourceEditVM nvm = e.NewValue as ResourceEditVM;
            if (nvm != null)
            {                
                nvm.RequestScrollToView += new Action<Resxus.Model.ResourceRecord>(vm_RequestScrollToView);
            }
        }

        void vm_RequestScrollToView(Resxus.Model.ResourceRecord obj)
        {            
            this.RecordGrid.ScrollIntoView(obj);
            this.RecordGrid.SelectedItem = obj;
        }

        private void txtSearch_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
            {
                BindingExpression be = txtSearch.GetBindingExpression(TextBox.TextProperty);
                be.UpdateSource();
            }
        }    

    }
}
